matplotlib time series plot
Official Documents
matplotlib.dates https://matplotlib.org/api/dates_api.html
YearLocator https://matplotlib.org/api/dates_api.html?highlight=yearlocator#matplotlib.dates.YearLocator
code:python
import matplotlib.dates as mdates
years = mdates.YearLocator(2) # every 2year
yearsFmt = mdates.DateFormatter('%Y')
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yearsFmt)
MonthLocator https://matplotlib.org/api/dates_api.html?highlight=yearlocator#matplotlib.dates.MonthLocator
Offifial examples
api example code: date_demo.py
https://matplotlib.org/examples/api/date_demo.html
pylab_examples example code: centered_ticklabels.py
https://matplotlib.org/examples/pylab_examples/centered_ticklabels.html
Custom tick formatter for time series — Matplotlib 2.1.2 documentation
https://matplotlib.org/gallery/api/date_index_formatter.html
Examples
Customize Matplotlibe Dates Ticks on the x-axis in Python | Earth Data Science - Earth Lab
https://www.earthdatascience.org/courses/earth-analytics-python/use-time-series-data-in-python/customize-dates--matplotlib-plots-python/
python - Controlling bars width in matplotlib with per-month data - Stack Overflow
https://stackoverflow.com/questions/886716/controlling-bars-width-in-matplotlib-with-per-month-data
matplotlibを使って時系列グラフを書いてみる - Qiita
https://qiita.com/drwtsn64/items/9fff27509ceb3c67b17b
MetPy Mondays #203 - Setting rcParams in the Notebook for Better Plots : Unidata Developer's Blog
code:python
import matplotlib.dates as mdates
hours=mdates.HourLocater(np.arange(0,24,2))
days=mdates.DayLocater(interval=1)
h_fmt=mdates.Dateformatter('%m/%d')
d_fmt=mdates.Dateformatter('')
ax.xaxis.set_minor_locator(hours)
ax.xaxis.set_major_locator(days)
ax.xaxis.set_minor_formatter(h_fmt)
ax.xaxis.set_major_formatter(d_fmt)
Tips
change style
code: python
plt.style.set("fivethirtyeigh")
see matplotlib style
Error "signed integer is greater than maximum"
python - Plot numpy datetime64 with matplotlib - Stack Overflow
https://stackoverflow.com/questions/11376080/plot-numpy-datetime64-with-matplotlib
code:python
from datetime import datetime
a=np.datetime64('2002-06-28').astype(datetime)
plot_date(a,2)
Paid Tutorial
Visualizing Time Series Data in Python | DataCamp
https://www.datacamp.com/courses/visualizing-time-series-data-in-python
See also
pandas timeseries
nc-time-axis
statsmodels.graphics.tsaplots